<?php
class brand {

	var $CI;
	var $brand_model;

	public function __construct() {
		$this->CI =& get_instance();
		$this->CI->load->model("sys/sys_brand_model");
		$this->brand_model =$this->CI->sys_brand_model;
	}


	public function save_brand($brand){
		$check_result=$this->check_brand($brand);
		if (!$check_result['result']) {
			return $check_result;
		}
		$brand_id =$this->brand_model->insert_brand($brand);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_brand_manage/brand_list";
		return $result;
	}

	public function check_brand($brand,$brand_id=""){
		$result['result'] =true;
		$result['message']="制作工艺名称可以使用";
		if ($brand['brand_name']=="") {
			$result['result']=false;
			$result['message']="制作工艺名称不能为空";
			return $result;
		}
		$brand_info =$this->get_brand_info_by_name($brand['brand_name']);
		if ($brand_info=="") {
			$result['result']=true;
			$result['message']="制作工艺名称可以使用";
			return $result;
		}
		if ($brand_info['brand_id']!=$brand_id) {
			$result['result']=false;
			$result['message']="制作工艺已经存在,请重新输入";
			return $result;
		}
		return $result;
	}


	public function query_brand_info($brand_id){
		return $this->brand_model->query_brand_info($brand_id);
	}

	public function get_brand_info_by_name($brand_name){
		return $this->brand_model->query_brand_info_by_name($brand_name);
	}

	public function set_delete_brand($brand_id){
		$this->brand_model->set_delete_brand($brand_id);

	}
	public function update_brand($brand,$brand_id){
		$check_result=$this->check_brand($brand,$brand_id);
		if (!$check_result['result']) {
			return $check_result;
		}
		$brand_id =$this->brand_model->update_brand($brand,$brand_id);
		$result['result']=true;
		$result['redirect_url']=base_url()."index.php/sys_brand_manage/brand_list";
		return $result;
	}

	public function query_brand_list(){
		$start		=	intval($this->CI->input->get("per_page"));
		$limit		=	$this->CI->config->item("page_size");
		return	$this->brand_model->query_brand_list($start,$limit);
	}
	public function query_brand_num(){
		return $this->brand_model->query_brand_num();
	}
	public function search_brand($keyword) {
		return $this->brand_model->search_brand($keyword);
	}
	
	
}
?>